package com.isoft.c2team3service2.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.isoft.c2team3service2.dto.CommentDTO;
import com.isoft.c2team3service2.entity.Comment;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface CommentMapper extends BaseMapper<Comment> {

    @Select(
            "SELECT c.* , h.photo AS photo FROM comment AS c " +
                    "JOIN tb_head h ON c.user_id = h.user_id " +
                    "WHERE c.post_id = #{postId} AND c.status = 1 " +
                    "ORDER BY c.create_time DESC "
    )
    List<CommentDTO>getCommentsByPostId(@Param("postId") Integer postId);
//    List<Comment> comments = lambdaQuery()
//            .eq(Comment::getPostId, postId) // 关联帖子ID
//            .eq(Comment::getStatus, 1) // 只查正常状态的评论
//            .orderByDesc(Comment::getCreateTime) // 最新评论在前
//            .list();
}